package br.usp.pcs.acs.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.core.client.GWT;
import br.usp.pcs.acs.client.MyImages;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.Image;
import br.usp.pcs.acs.client.FlightListPanel;
import br.usp.pcs.acs.client.FlightInfo;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class ACS implements EntryPoint {
	
	private static ACS singleton;
	
	/**
	* Gets the singleton Mail instance.
	*/
	public static ACS get() {
	    return singleton;
	}
	
	private static final MyImages myImages = GWT.create(MyImages.class);
	private HorizontalPanel topHorizontalPanel;
	private FlexTable elementsFlexTable;
	private HorizontalPanel bottomHorizontalPanel;
	private FlightListPanel flightListPanel;
	private HorizontalPanel searchHorizontalPanel;
	private CAHome caHomeTab;
	private GAHome gaHomeTab;
	
	/**
	* An aggragate image bundle that pulls together all the images for this
	* application into a single bundle.
	*/
	public interface Images{
	}
	    
	/**
	* Displays the specified item.
	*
	* @param item
	*/
	public void displayFlight(FlightInfo item) {
		//flightInfo.setItem(item);
	}
	
	public FlexTable getElementsFlexTable(){
		return elementsFlexTable;
	}

	public void onModuleLoad() {
		
		singleton = this;
		
		RootPanel rootPanel = RootPanel.get();
		{
			topHorizontalPanel = new HorizontalPanel();
			rootPanel.add(topHorizontalPanel, 5, 5);
			topHorizontalPanel.setStyleName("topHorizontalPanel");
			topHorizontalPanel.setSize("99.2%", "60px");
			{
				elementsFlexTable = new FlexTable();
				topHorizontalPanel.add(elementsFlexTable);
				elementsFlexTable.setSize("100%", "100%");
				{
					LoginPanel loginPanel = new LoginPanel();
					elementsFlexTable.setWidget(0, 0, loginPanel);
				}
				{
					HorizontalPanel titleAcsHorizontalPanel = new HorizontalPanel();
					elementsFlexTable.setWidget(0, 1, titleAcsHorizontalPanel);
					{
						FlexTable flexTable_1 = new FlexTable();
						titleAcsHorizontalPanel.add(flexTable_1);
						{
							Label lblAcs = new Label("ACS");
							flexTable_1.setWidget(0, 0, lblAcs);
							lblAcs.setStyleName("gwt-Label-ACS");
							lblAcs.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
						}
						{
							Label lblAirportControl = new Label("Airport Control");
							flexTable_1.setWidget(1, 0, lblAirportControl);
							lblAirportControl.setStyleName("gwt-Label-AirportControlSystem");
							lblAirportControl.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
						}
						{
							Label lblSystem = new Label("System");
							flexTable_1.setWidget(2, 0, lblSystem);
							lblSystem.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
							lblSystem.setStyleName("gwt-Label-AirportControlSystem");
						}
					}
				}
				{
					HorizontalPanel logoHorizontalPanel = new HorizontalPanel();
					elementsFlexTable.setWidget(0, 2, logoHorizontalPanel);
					{
						Image image = myImages.logo().createImage();
						logoHorizontalPanel.add(image);
					}
				}
				{
					searchHorizontalPanel = new HorizontalPanel();
					elementsFlexTable.setWidget(0, 3, searchHorizontalPanel);
					searchHorizontalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
					{
						addSearchPanel();
					}
				}
			}
		}
		{
			bottomHorizontalPanel = new HorizontalPanel();
			rootPanel.add(bottomHorizontalPanel, 5, 153);
			bottomHorizontalPanel.setSize("99.2%", "277px");
			{
				addFlightList();
			}
		}
	}
	
	public void removeSearchPanel(){
		searchHorizontalPanel.clear();
    }
	
	public void addSearchPanel(){
		SearchPanel searchPanel = new SearchPanel();
		searchHorizontalPanel.add(searchPanel);
	}
	
	public void removeBottomPanel(){
		bottomHorizontalPanel.clear();
    }

    public void addFlightList(){

    	flightListPanel = new FlightListPanel();
		bottomHorizontalPanel.add(flightListPanel);
		flightListPanel.setWidth("100%");
    }
    
    public void addCAHome(){

    	caHomeTab = new CAHome();
		bottomHorizontalPanel.add(caHomeTab);
		caHomeTab.setWidth("100%");
    }
    
    public void addGAHome(){

    	gaHomeTab = new GAHome();
		bottomHorizontalPanel.add(gaHomeTab);
		gaHomeTab.setWidth("100%");
    }
}
